﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enterprise.Framework.Cache;
using Resto.CostControl.Core.Facade.DishModule.DataTransferObject;
using Enterprise.Framework.Core.Container;
using Resto.CostControl.Core.Domain.Query.DishModule;
using Resto.CostControl.Core.Domain.Model;

namespace Resto.CostControl.Core.Cache
{
    internal class DishDTOCache : ObjectCache<DishDTO, DishDTOCache>
    {
        static DishDTOCache()
        {
            OnCacheObjectNotFound += FindObject;
        }

        protected override string CacheKey_Prefix
        {
            get { return "DishDTOCacheKey_"; }
        }

        protected override CacheMode CacheMode
        {
            get { return CacheMode.DistributedContext; }
        }


        /// <summary>
        /// 从数据库中查询微博信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private static void FindObject(object sender, CacheEventArgs args)
        {
            DishDQO dishDQO = ObjectCreator.Create<DishDQO>();
            Dish dish = dishDQO.GetDishOrDefault(args.Key);
            if (dish != null)
            {
                args.CacheObject = new DishDTO(dish);
            }
        }

        //public static DishDTO Get(int id)
        //{
        //    return Get(id.ToString());
        //}

        //public static void Remove(int id)
        //{
        //    Remove(id.ToString());
        //}
    }
}
